﻿using System.Security.Claims;
using System.Threading;
using K9Nano.Runtime;
using Microsoft.AspNetCore.Http;

namespace K9Nano.AspNetCore.Runtime
{
    public class HttpClaimAccessor : IClaimAccessor
    {
        private readonly IHttpContextAccessor _httpContextAccessor;

        public HttpClaimAccessor(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }

        public ClaimsPrincipal ClaimsPrincipal =>
            _httpContextAccessor.HttpContext?.User ?? (Thread.CurrentPrincipal as ClaimsPrincipal);
    }
}